﻿using Core.IRepository;
using Core.IServices;
using Library.Cache;
using Library.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNet.Identity;
using Core.Dtos;
using Microsoft.AspNet.Identity.EntityFramework;
using Core.Messages;
using Core.Domain;
using Core.Queries;
using Core.Aspects;

namespace Services
{
    [CacheName("Role")]
    public class ManageRoleService : BaseService, IManageRoleService
    {
        private readonly IRoleRepository repository;
        private readonly IUnitOfWork unitOfWork;
        private readonly IGenericReaderService<string, Role, RoleDto, RoleQuery> readerService;
        private readonly IGenericWriterService<string, Role, RoleDto, RoleQuery> writerService;

        public ManageRoleService(INullUnitOfWork unitOfWork, IRoleRepository repository, IGenericReaderService<string, Role, RoleDto, RoleQuery> readerService, IGenericWriterService<string, Role, RoleDto, RoleQuery> writerService)
        {
            this.repository = repository;
            this.unitOfWork = unitOfWork;
            this.readerService = readerService;
            this.writerService = writerService;
            readerService.Initialize(unitOfWork, repository);
            writerService.Initialize(unitOfWork, repository);
        }

        [Cache]
        public RoleDto FindByID(string id)
        {
            return readerService.FindByID(id);
        }

        public QueryResponse<RoleDto> FindBy(Request<RoleQuery> request)
        {
            return readerService.FindBy(request);
        }

        public Response<string> Add(Request<RoleDto> dto)
        {
            return writerService.Add(dto);
        }

        [DeleteCache]
        public Response Edit(string id, Request<RoleDto> dto)
        {
            return writerService.Edit(id, dto);
        }

        [DeleteCache]
        public Response Delete(string id)
        {
            return writerService.Delete(id);
        }
    }
}
